#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------


def init(module):
    module.name = ":driver:adc_sampler"
    module.description = """\
# ADC Sampler

This template class stores 8, 16 or 32bit ADC values in a buffer and
provides an easy interface for managing that data.

The code will read the ADC channels you specify in an array.
This means you can remap the ADC channels in the order that they
should appear in the buffer.
The array must obviously have as many elements as channels!
For example, if channels 0,2,7 are connected, but the sensors
are in the wrong order, just remap them with the array {7,0,2}.

To make use of oversampling and averaging, set `Oversamples > 0`.
This will loop `Oversamples` times through the ADC channels, adding
the average of each result to the buffer.

This class will choose the smallest data width for you.
It decides this by adding the ADC resolution and the oversample size
and choosing the next smallest size (not larger than 32bit though!).

!!!warning
    The averaging algorithm only works for unsigned ADC data!
"""


def prepare(module, options):
    module.depends(
        ":architecture:adc",
        ":math:utils",
        ":utils")
    return True

def build(env):
    env.outbasepath = "modm/src/modm/driver/adc"
    env.copy("adc_sampler.hpp")
    env.copy("adc_sampler_impl.hpp")
